package com.test.daily.leetcode.y2022.m07.day0701.day0702.home.v01;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;

/**
 * @author Tom on 2022/7/2
 */
public class Solution {

    public String predictPartyVictory(String senate) {
        Queue<Integer> rQueue = new LinkedList<>();
        Queue<Integer> dQueue = new LinkedList<>();
        int n = senate.length();
        for (int i = 0; i < senate.length(); i++) {
            if(senate.charAt(i) == 'D'){
                dQueue.offer(i);
            } else {
                rQueue.offer(i);
            }
        }
        while(!rQueue.isEmpty() && !dQueue.isEmpty()){
            int dIndex = dQueue.poll();
            int rIndex = rQueue.poll();
            if(dIndex < rIndex){
                dQueue.offer(dIndex + n);
            } else {
                rQueue.offer(rIndex + n);
            }
        }
        return rQueue.isEmpty() ? "Dire":"Radiant";
    }
}
